<?php
class Connection{
	public $result;
	
	function requestdata($query){
		$user = "root";
        $password = "";
        $database = "fbdemodatabase";
        $connect = mysql_connect("localhost",$user,$password);
        mysql_query("set names 'utf8'");
        mysql_select_db($database) or die( "Unable to select database");
        
		$this->result = mysql_query($query);
		
		mysql_close($connect);
		return $this->result;
	}

}
// User class --------------------------------------
class User{
	public  $userid;
	public  $name;
	public  $imgUrl;
	
	function setUserid($userId){
		$this->userid = $userId;
	}
	function getUserid(){
		return $this->userid;
	}
	
	function setName($name){
		$this->name = $name;
	}
	function getName(){
		return $this->name;
	}
	
	function setImgUrl($imgUrl){
		$this->imgUrl = $imgUrl;
	}
	function getImgUrl(){
		return $this->imgUrl;
	}
	function __construct($userid,$name,$imgUrl){
		$this->userid = $userid;
		$this->name = $name;
		$this->imgUrl = $imgUrl;
	}
	function showUserInPost($friendpost){
		if ($friendpost){
			echo '<div class="userinfoframe">
                  <img class="profileImage" src="'.$this->imgUrl.'"></img>
                  <a class="profileName" href="personPage.php?useridperson='.$this->userid.'" >'.$this->name.'</a>
                  <div class="posttofriend"></div><a class="profileName" float="inline" href="personPage.php?useridperson='.$friendpost->userid.'" >'.$friendpost->name.'</a>
              </div>';
		}
		else{
			echo '<div class="userinfoframe">
                  <img class="profileImage" src="'.$this->imgUrl.'"></img>
                  <a class="profileName" href="personPage.php?useridperson='.$this->userid.'" >'.$this->name.'</a>
              </div>';
		}
		
	}
}
// Post class -------------------------------------------

class Post{
	public $postid;
	public $userpost;
	public $postcontent;
	public $postImgUrl;
	public $posttime;
	public $ispublic;
	public $likenumber;
	public $friendpost;
	
	function setpostid($postid){
		$this->postid = $postid;
	}
	function getpostid(){
	    return $this->postid;
	}
	
	function setuserpost($userpost){
	    $this->userpost = $userpost;
	}
	function getuserpost(){
	    return $this->userpost;
	}
	function setpostcontent($postcontent){
	    $this->postcontent = $postcontent;
	}
	function getpostcontent(){
	    return $this->postcontent;
	}
	function setpostImgUrl($postImgUrl){
	    $this->postImgUrl = $postImgUrl;
	}
	function getpostImgUrl(){
	    return $this->postImgUrl;
	}
	function setposttime($posttime){
	    $this->posttime = $posttime;
	}
	function getposttime(){
	    return $this->posttime;
	}
	function setispublic($ispublic){
	    $this->ispublic = $ispublic;
	}
	function getispublic(){
	    return $this->ispublic;
	}
	function setlikenumber($likenumber){
	    $this->likenumber = $likenumber;
	}
	function getlikenumber(){
	    return $this->likenumber;
	}
	function setfriendpost($friendpost){
		$this->friendpost = $friendpost;
	}
	function getfriendpost(){
		return $this->friendpost;
	}
	function __construct($postid,$userpost,$postcontent,$postImgUrl,$posttime,$friendpost){
		$this->setpostid($postid);
		$this->setuserpost($userpost);
		$this->setpostcontent($postcontent);
		$this->setpostImgUrl($postImgUrl);
		$this->setposttime($posttime);
		$this->setfriendpost($friendpost);
	}
	function showPost(){
		echo '<div class="postframe">';
		$this->userpost->showUserInPost($this->friendpost);
		if ($this->postImgUrl){
			echo '<div class="clear"></div>
              <div class="postcontent">'.$this->postcontent.'</div>
              <img class="postimage" src="'.$this->postImgUrl.'">
              <div class="postaction">
                 <a class="postactionelement" href="#">Like</a>
                 <a class="postactionelement" href="#">Comment</a>
                 <div class="posttime">'.$this->posttime.'</div>
              <div class="clear"></div>
              </div>';
		}
		else{
			echo '<div class="clear"></div>
              <div class="postcontent">'.$this->postcontent.'</div>
              <div class="postaction">
                 <a class="postactionelement" href="#">Like</a>
                 <a class="postactionelement" href="#">Comment</a>
                 <div class="posttime">'.$this->posttime.'</div>
              <div class="clear"></div>
              </div>';
		}

		echo '</div>';
	}
}

?>
